package com.example.gcjjhd.agriculture.controller;
import com.example.gcjjhd.agriculture.entity.Device;
import com.example.gcjjhd.agriculture.service.DeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/api/devices")
@CrossOrigin
public class DeviceController {
    @Autowired
    private DeviceService deviceService;

    @GetMapping
    public List<Device> getAllDevices() {
        return deviceService.getAllDevices();
    }

    @GetMapping("/{id}")
    public Device getDeviceById(@PathVariable String id) {
        return deviceService.getDeviceById(id);
    }

    @GetMapping("/type/{type}")
    public List<Device> getDevicesByType(@PathVariable String type) {
        return deviceService.getDevicesByType(type);
    }
}